//
//  SIEmoticonTipVIew.swift
//  SinaImiate
//
//  Created by xiaoming on 16/7/15.
//  Copyright © 2016年 GoodJob. All rights reserved.
//

import UIKit
import pop

/// 表情选择提示视图;
class SIEmoticonTipVIew: UIImageView {
    
    private var preEmoticon: SIEmoticon?
    
    var emoticon: SIEmoticon? {
        
        didSet {
            if emoticon == preEmoticon {
                
                return
                
            }
            
            preEmoticon = emoticon
            
            tipButton.setTitle(emoticon?.emoji, for: [])
            tipButton.setImage(emoticon?.image, for: [])
            
            print("设置表情动画")
            
            let anim: POPSpringAnimation = POPSpringAnimation(propertyNamed: kPOPLayerPositionY)
            
            anim.fromValue = 30
            anim.toValue = 8
            anim.springBounciness = 20
            anim.springSpeed = 20
            
            tipButton.layer.pop_add(anim, forKey: nil)

        }
        
    }
    
    // MARK: - 私有控件
    private lazy var tipButton = UIButton()

    // MARK: - 构造函数
    init() {
        
        let bundle  = SIEmotionManager.shared.bundle
        
        let image = UIImage(named: "emoticon_keyboard_magnifier", in: bundle, compatibleWith: nil)
        
        super.init(image: image)
        
        layer.anchorPoint = CGPoint(x: 0.5, y: 1.2)
        
        tipButton.layer.anchorPoint = CGPoint(x: 0.5, y: 0)
        
        tipButton.frame = CGRect(x: 0, y: 0, width: 36, height: 36)
        
        tipButton.center.x = bounds.width * 0.5
        
        tipButton.setTitle("🌎", for: [])
        
        tipButton.titleLabel?.font = UIFont.systemFont(ofSize: 32)
        
        addSubview(tipButton)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
